var year = Number(prompt("请输入年份"));
var month = Number(prompt("请输入月份"));



var days = 0;
for(var i = 1980;i < year;i++){
    if(i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
        days += 366;
    }else{
        days += 365;
    }
}


for(var i = 1;i < month;i++){
    switch (i){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            days += 31;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            days += 30;
            break;
        case 2:
            if(year % 4 ==0 && year % 100 != 0 || year % 400 ==0){
                days += 29;
            }else {
                days += 28;
            }
    }
}

var yuShu = (days  + 2) % 7;

var shangDay = 0;
var shangYue = month - 1 == 0 ? 12 : month - 1;
switch (shangYue){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        shangDay += 31;
        break;
    case 4:
    case 6:
    case 9:
    case 11:
        shangDay += 30;
        break;
    case 2:
        if(year % 4 ==0 && year % 100 != 0 || year % 400 ==0){
            shangDay += 29;
        }else {
            shangDay += 28;
        }
}


var thisDay = 0;
switch (month){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        thisDay += 31;
        break;
    case 4:
    case 6:
    case 9:
    case 11:
        thisDay += 30;
        break;
    case 2:
        if(year % 4 ==0 && year % 100 != 0 || year % 400 ==0){
            thisDay += 29;
        }else {
            thisDay += 28;
        }
}




var day = document.querySelector("#day");



for(var i = shangDay - yuShu + 1;i <= shangDay;i++){
    day.innerHTML += '<span class="h">'+ i +'</span>';
}


var today = new Date().getDate();
for(var i = 1;i <= thisDay;i++){
    if(i == today){
        day.innerHTML += '<span class="today">'+ i +'</span>';
    }else{
        day.innerHTML += '<span>'+ i +'</span>';
    }
}



for(var i = 1;i <= 42 - thisDay - yuShu;i++){
    day.innerHTML += '<span class="h">'+ i +'</span>';
}




document.querySelector("#span").innerHTML = year;
document.querySelector("#span1").innerHTML = month;